package net.aspw.client.features.module.impl.exploit

import net.aspw.client.event.ClickBlockEvent
import net.aspw.client.event.EventState
import net.aspw.client.event.EventTarget
import net.aspw.client.event.MotionEvent
import net.aspw.client.features.module.Module
import net.aspw.client.features.module.ModuleCategory
import net.aspw.client.features.module.ModuleInfo
import net.aspw.client.utils.PacketUtils
import net.minecraft.network.play.client.C07PacketPlayerDigging
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumFacing

@ModuleInfo(name = "PacketMine", spacedName = "Packet Mine", category = ModuleCategory.EXPLOIT)
class PacketMine : Module() {
    private var blockPos: BlockPos? = null

    @EventTarget
    fun onBlockClick(event: ClickBlockEvent) {
        blockPos = event.clickedBlock
    }

    override fun onDisable() {
        blockPos ?: return
        blockPos = null
    }

    @EventTarget
    fun onMotion(event: MotionEvent) {
        if (event.eventState == EventState.POST && blockPos != null) {
            repeat(2) {
                PacketUtils.sendPacketNoEvent(
                    C07PacketPlayerDigging(
                        C07PacketPlayerDigging.Action.STOP_DESTROY_BLOCK,
                        blockPos,
                        EnumFacing.DOWN
                    )
                )
            }
            blockPos = null
        }
    }
}